package models.statistics;

import exceptions.InvalidParameterException;
import models.CompressionAlgorithmType;
import models.FileInfo;

import javax.persistence.*;

@Entity
@Table(name = "SLPClassicStatistics")
public class SLPClassicStatistics extends CompressionStatsBase implements ISLPUsingAVLCompressionStats {


    @Id
    @Column(name = "id", length = 50)
    public String id;

    @Column(name = "compressedFileSize")
    public long compressedFileSize;

    @Column(name = "slpBuildingTime")
    public long slpBuildingTime;

    @Column(name = "dataFactoryType", length = 50)
    public String dataFactoryType;

    @Column(name = "rebalanceCount")
    public int rebalanceCount;

    @Column(name = "height")
    public long height;

    @OneToOne(cascade = CascadeType.ALL)
    public FileInfo fileInfo;

    public SLPClassicStatistics() {
    }

    public SLPClassicStatistics(String id, long copmressedFileSize, long slpBuildingTime,
                                String dataFactoryType, int rebalanceCount, long height, FileInfo fileInfo) {
        this.id = id;
        this.compressedFileSize = copmressedFileSize;
        this.slpBuildingTime = slpBuildingTime;
        this.dataFactoryType = dataFactoryType;
        this.rebalanceCount = rebalanceCount;
        this.height = height;
        this.fileInfo = fileInfo;
    }

    @Override
    public int slpHeight() {
        return (int) height;
    }

    @Override
    public long calcTextSize(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(fileInfo.fileSize, reductionRate);
    }

    @Override
    public float calcCompressionRate() {
        return calcCompressionRate(fileInfo.fileSize, compressedFileSize);
    }

    @Override
    public long calcCompressionTime(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(slpBuildingTime, reductionRate);
    }

    @Override
    public long getAVLRotationsNumber(int reductionRate) throws InvalidParameterException {
        return rebalanceCount;
    }

    @Override
    public CompressionAlgorithmType algorithmType() {
        return CompressionAlgorithmType.slpClassic;
    }
}
